package com.edu.controller;

import com.edu.common.Result;
import com.edu.entity.Email;
import com.edu.properties.MyUserDetails;
import com.edu.service.CommonService;
import com.edu.service.IEmailService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.Authentication;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.List;

@Controller
@Slf4j
public class CommonController {
    @Autowired
    private CommonService commmonService;
    /**
     * 文件上传
     *
     * @param file 前端传过来的文件
     * @return
     */

    @PostMapping("/upload")
    public Result<String> upload(MultipartFile file)   {
        log.info("文件上传{}", file);
        String filePath;
        try {
            filePath = commmonService.upload(file);
        } catch (IOException e) {
            return Result.error("文件上传失败");
        }
        return Result.success(filePath);
    }

}
